
const Actor = require("./Actor");
const Utils = require("./module/Utils");

cc.Class({
    // 继承 Actor，相当于将 Actor 挂载到节点上
    extends: Actor,

    properties: {
        // 手上最接近 21 点的点数（有可能超过 21 点）
        bestPoint: {
            get: function () {
                const cards = this.holeCard ? [this.holeCard].concat(this.cards) : this.cards;
                const minMax = Utils.getMinMaxPoint(cards);
                return minMax.max;
            },
            // 重载
            override: true,
        },
    },

    init: function () {
        cc.log('init dealer.js');
        this._super();
        this.renderer.initDealer();
    },

    // 返回是否要牌
    wantHit: function () {
        const Game = require('./Game');
        const Types = require('./module/Types');
        const bestPoint = this.bestPoint;

        if (bestPoint === 21) {
            // 最大点
            return false;
        }
        // 不论抽到什么牌肯定不会爆,接着抽
        if (bestPoint <= 21 - 10) {
            return true;
        }

        const player = Game.instance.player;
        const outcome = Game.instance._getPlayerResult(player, this);

        switch (outcome) {
            case Types.Outcome.Win:
                return true;
            case Types.Outcome.Lose:
                return false;
        }
        return this.bestPoint < 17;

    }


});
